<template>
  <div class="box5">
    <div class="title">
      <p>未来七天游客趋势</p>
      <img src="../../images/dataScreen-title.png" alt="" />
    </div>

    <div class="charts" ref="line"></div>
  </div>
</template>

<script setup lang="ts">
import * as echarts from "echarts";
import { ref, onMounted } from "vue";

// 获取Ref节点
let line = ref();

onMounted(() => {
  initChart();
});

const initChart = () => {
  let mycharts = echarts.init(line.value);

  //设置配置项
  mycharts.setOption({
    // 标题组件
    title: {
      text: "访问量",
    },
    // X |y轴
    xAxis: {
      type: "category",
      // 两侧不留白
      boundaryGap: false,
      //分割线不要
      splitLine: {
        show: false,
      },
      data: ["周一", "周二", "周三", "周四", "周五", "周六"],
    },
    yAxis: {
      splitLine: {
        show: false,
      },
      // 轴线的位置
      axisLine: {
        show: true,
      },
      // 刻度
      axisTick: {
        show: true,
      },
    },
    grid: {
      left: 0,
      right: 0,
      top: 0,
      bottom: 0,
    },
    series: [
      {
        type: "line",
        data: [0, 120, 1240, 894, 475, 12],
        // 平滑曲线的设置
        smooth: true,
        // 区域填充样式
        areaStyle: {
          color: {
            type: "linear",
            x: 0,
            y: 0,
            x2: 0,
            y2: 1,
            colorStops: [
              {
                offset: 0,
                color: "red", //0%处的颜色
              },
              {
                offset: 1,
                color: "blue",
              },
            ],
            global: false,
          },
        },
      },
    ],
  });
};
</script>

<style scoped lang="scss">
.box5 {
  width: 100%;
  height: 100%;
  background: url(../../images/dataScreen-main-cb.png) no-repeat;
  background-size: 100% 100%;
  margin: 0 20px;

  .title {
    margin-left: 20px;

    p {
      color: white;
      font-size: 20px;
    }
  }

  .charts {
    width: 100%;
    height: calc(100% - 20px);
  }
}
</style>
